$(function () {


    //TODO 基本信息修改保存
    $('.basic_info').click(function () {
        // 防止form冲突
        event.preventDefault();
        // var name = $('#name').val();    // 真实姓名
        // var gender = $('#gender').val();    //  性别
        // var education = $('#select_topDegree').val();  // 学历
        // var edu_age = $('#select_workyear').val(); // 学龄
        // var b_mobile = $('#tel').val(); // 联系手机
        // var b_email = $('#email').val(); // 联系邮箱
        // var cur_status = $('#select_currentState').val(); // 联系邮箱
        // //提交信息
        // var params = {
        //     "name": name,
        //     "gender": gender,
        //     "education": education,
        //     "edu_age": edu_age,
        //     "b_mobile": b_mobile,
        //     "b_email": b_email,
        //     "cur_status": cur_status,
        // "csrfmiddlewaretoken": $("*[name='csrfmiddlewaretoken']").val(),
        // };
        $('#profileForm').ajaxSubmit({
            url: "/userbasicinfo/",
            type: "post",
            // data: JSON.stringify(params),
            headers: {
                'X-CSRFToken': $.cookie('csrftoken')
            },
            // async: false,
            // contentType: "application/json",
            success: function (resp) {
                if (resp.errno == "0") {
                    alert('修改成功');
                    $('.basicEdit').hide();
                    $('.basicShow').show();
                } else {
                    alert(resp.errmsg)
                }
            },
        });

    });

    //TODO 期望工作修改
    $('.expect_work').click(function () {
        // 防止form冲突
        event.preventDefault();
        var city = $('#select_expectCity').val();   // 期望城市
        // var work_kind = $('.kind').val(); // 工作方式
        var work_kind = $("input[name='work_type']:checked").val();
        var position = $("#expectPosition").val(); // 职位
        var salary = $('#select_expectSalary').val(); // 薪资

        if (salary == '期望月薪') {
            alert('请填写期望月薪');
            return;
        }

        //提交信息
        var params = {
            "city": city,
            "work_kind": work_kind,
            "position": position,
            "salary": salary,
            "csrfmiddlewaretoken": $("*[name='csrfmiddlewaretoken']").val(),
        };
        $.ajax({
            url: "/userexpectwork/",
            type: "post",
            data: JSON.stringify(params),
            headers: {
                'X-CSRFToken': $.cookie('csrftoken')
            },
            async: false,
            contentType: "application/json",
            success: function (resp) {
                if (resp.errno == "0") {
                    alert('修改成功');
                    $('.expectEdit').hide();
                    $('.expectAdd').show();
                } else {
                    alert(resp.errmsg)
                }
            },
        });

    });

    //TODO 工作经历修改
    $('.work_exp').click(function () {
        // 防止form冲突
        event.preventDefault();
        var company_name = $(".company").val();  // 公司名称
        var job_name = $(".position").val(); // 职位
        var startyear = $('.select_companyYearStart').val(); // 起始年份
        var startmonth = $('.select_companyMonthStart').val(); // 起始月份
        var endyear = $('.companyYearEnd').val(); // 结束年份
        var endmonth = $('.select_companyMonthEnd').val(); // 结束月份
        //提交信息
        var params = {
            "company_name": company_name,
            "job_name": job_name,
            "startyear": startyear,
            "startmonth": startmonth,
            "endyear": endyear,
            "endmonth": endmonth,
            "csrfmiddlewaretoken": $("*[name='csrfmiddlewaretoken']").val(),
        };

        // alert(startmonth);
        // alert(endmonth);

        if (startmonth == '开始月份') {
            alert('请填写开始月份');
            return;
        }
        if (endmonth == '结束月份' && endyear != '至今') {
            alert('请填写结束月份');
            return;
        }


        $.ajax({
            url: "/updateworkexp/",
            type: "post",
            data: JSON.stringify(params),
            headers: {
                'X-CSRFToken': $.cookie('csrftoken')
            },
            async: false,
            contentType: "application/json",
            success: function (resp) {
                if (resp.errno == "0") {
                    alert('修改成功');
                    $('.experienceEdit').hide();
                    $('.experienceAdd').show();
                } else {
                    alert(resp.errmsg)
                }
            },
        });

    });

    //TODO 项目经验修改
    $('.pro_exp').click(function () {
        // 防止form冲突
        event.preventDefault();
        var pro_name = $(".pro_name").val();  // 项目名称
        var post_name = $(".post_name").val(); // 担任职务
        var pro_start_year = $('.pro_start_year').val(); // 起始年份
        var pro_start_month = $('.pro_start_month').val(); // 起始月份
        var pro_year_end = $('.projectYearEnd').val(); // 结束年份
        var pro_month_end = $('.projectMonthEnd').val(); // 结束月份
        var content = $('.projectDescription').val(); // 项目描述
        //提交信息
        var params = {
            "pro_name": pro_name,
            "post_name": post_name,
            "pro_start_year": pro_start_year,
            "pro_start_month": pro_start_month,
            "pro_year_end": pro_year_end,
            "pro_month_end": pro_month_end,
            "content": content,
            "csrfmiddlewaretoken": $("*[name='csrfmiddlewaretoken']").val(),
        };
        $.ajax({
            url: "/updateproexp/",
            type: "post",
            data: JSON.stringify(params),
            headers: {
                'X-CSRFToken': $.cookie('csrftoken')
            },
            async: false,
            contentType: "application/json",
            success: function (resp) {
                if (resp.errno == "0") {
                    alert('修改成功');
                    $('.projectEdit').hide();
                    $('.projectAdd').show();
                } else {
                    alert(resp.errmsg)
                }
            },
        });

    });

    // TODO 教育背景修改
    $('.edu_bk').click(function () {
        event.preventDefault();

        $('#edu02form').ajaxSubmit({
            url: "/updateedubk/",
            type: "post",
            // data: JSON.stringify(params),
            headers: {
                'X-CSRFToken': $.cookie('csrftoken')
            },
            // async: false,
            // contentType: "application/json",
            success: function (resp) {
                if (resp.errno == "0") {
                    alert('修改成功');
                    $('.educationalEdit').hide();
                    $('.educationalAdd').show();
                } else {
                    alert(resp.errmsg)
                }
            },
        });
    });


    // TODO 自我描述修改
    $('.self_desc_btn').click(function () {
        event.preventDefault();

        $('#self_desc').ajaxSubmit({
            url: "/updateselfdesc/",
            type: "post",
            // data: JSON.stringify(params),
            headers: {
                'X-CSRFToken': $.cookie('csrftoken')
            },
            // async: false,
            // contentType: "application/json",
            success: function (resp) {
                if (resp.errno == "0") {
                    alert('修改成功');
                    $('.descriptionEdit').hide();
                    $('.descriptionAdd').show();
                } else {
                    alert(resp.errmsg)
                }
            },
        });
    });


    // TODO 作品展示修改
    $('.work_show_btn').click(function () {
        event.preventDefault();

        $('#works_show').ajaxSubmit({
            url: "/updateproductshow/",
            type: "post",
            // data: JSON.stringify(params),
            headers: {
                'X-CSRFToken': $.cookie('csrftoken')
            },
            // async: false,
            // contentType: "application/json",
            success: function (resp) {
                if (resp.errno == "0") {
                    alert('修改成功');
                    $('.workEdit').hide();
                    $('.workAdd').show();
                } else {
                    alert(resp.errmsg)
                }
            },
        });
    });

    // TODO 简历标题修改
    $('.title_btn').click(function () {
        event.preventDefault();

        $('.resume_title').ajaxSubmit({
            url: "/updateresumetitle/",
            type: "post",
            // data: JSON.stringify(params),
            headers: {
                'X-CSRFToken': $.cookie('csrftoken')
            },
            // async: false,
            // contentType: "application/json",
            success: function (resp) {
                if (resp.errno == "0") {
                    alert('修改成功');
                    $('#resumeNameForm').hide();
                    $('.nameShow').show();
                } else {
                    alert(resp.errmsg)
                }
            },
        });
    });
});


